<template>
    <div class="zs-table-page-container">
        <div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
            <span>
                <el-select v-model="companyPlatformId" class="zs-select-md zs-space-right-sm" placeholder="平台商名称"
                    filterable>
                    <el-option v-for="item in platList" :key="item.companyPlatformId" :label="item.companyPlatformName"
                        :value="item.companyPlatformId" />
                </el-select>
                <el-select v-model="projectName" class="zs-select-md zs-space-right-sm" placeholder="项目名称"
                    filterable clearable>
                    <el-option v-for="item in projectList" :key="item" :label="item"
                        :value="item" />
                </el-select>
                <el-select v-model="year" class="zs-select-md zs-space-right-sm" placeholder="年份"
                    filterable clearable>
                    <el-option v-for="item in yearList" :key="item" :label="item"
                        :value="item" />
                </el-select>
                <el-button class="zs-btn-plain" @click="getData()">
                    查询
                </el-button>
            </span>
        </div>
        <div class="zs-card zs-table-page-content">
            <el-table :data="tableData" class="zs-table-page-main" :stripe="stripe">
                <el-table-column label="序号" width="60" :align="'center'">
                    <template #default="scope">
                        {{ scope.$index + 1 + curPageSize * (currentPage - 1) }}
                    </template>
                </el-table-column>
                <el-table-column prop="projectName" label="项目名称" :align="'left'"></el-table-column>
                <el-table-column label="订单数量" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.orderNumCount) }}
                    </template>
                </el-table-column>
                <el-table-column label="订单金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.companyServiceDividePrice) }}
                    </template>
                </el-table-column>
                <el-table-column prop="" label="查看" width="150" :align="'right'">
                    <template #default="scope">
                        <el-button class="zs-link" link size="small" @click="goDetail(scope.row)">订单</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- <div class="zs-text-gray-dark zs-text-sm zs-space-top">*销售额：万元；客流量：万人次；车流量：车次</div> -->
            <div class="zs-space-top-sm zs-table-page-pagination">
                <el-pagination v-model:currentPage="currentPage" v-model:page-size="curPageSize" :page-sizes="curPageSizes"
                    :small="true" :background="true" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>
<script setup>
import dashBoardApi from '@/api/EnterpriseServices/dashBoard'
import detailApi from '@/api/EnterpriseServices/detailPages'
// import { ElMessage } from 'element-plus'
import { toThousands } from '@/utils/number-util'
import { ref } from 'vue'
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
let store = useStore()
const stripe = ref(true)
const route = useRoute().query

let companyPlatformId = ref(Number(route.companyPlatformId))
let companyPlatformName = ref('')
let platList = ref([])
let projectName = ref('')
let projectList = ref([])
let year = ref('')
let yearList = ref([])
// let startDate = ref('')
// let endDate = ref('')
// let valueFormat = ref('YYYY-MM')
// let pickerDate = ref('month')
const tableData = ref([])

// 分页
const curPageSizes = ref(store.state.uiPageSizes)
let curPageSize = ref(store.state.uiPageSizeDefault)
let currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
    curPageSize.value = val
    getList()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getList()
}

const getPlatList = async () => {
    await dashBoardApi.getCompanyPlatformListApi().then((res) => {
        if (res.data.code == 200) {
            platList.value = res.data.data
            const curPlat = platList.value.find(item => {
                return item.companyPlatformId == companyPlatformId.value
            })
            companyPlatformName.value = curPlat.companyPlatformName
        }
    })
}


const getProjectList = () => {
    detailApi.orderIncomeProjectDownApi(companyPlatformId.value).then((res) => {
        if (res.data.code == 200) {
            projectList.value = res.data.data
        }
    })
}

const getYearList = () => {
    detailApi.orderIncomeTimeDownApi(companyPlatformId.value).then((res) => {
        if (res.data.code == 200) {
            yearList.value = res.data.data
        }
    })
}


const getList = () => {
    // if (isSelect.value && ((startDate.value && !endDate.value) || (!startDate.value && endDate.value))) {
    //     ElMessage({
    //         message: '请选择开始日期和结束日期',
    //         type: 'warning',
    //     })
    //     return false
    // }
    // let start = isSelect.value ? startDate.value : route.startDate
    // let end = isSelect.value ? endDate.value : route.endDate

    const curPlat = platList.value.find(item => {
        return item.companyPlatformId == companyPlatformId.value
    })
    companyPlatformName.value = curPlat.companyPlatformName

    detailApi.orderIncomeListApi({ companyPlatformName: companyPlatformName.value, projectName: projectName.value, orderYear: year.value, pageNo: currentPage.value, pageSize: curPageSize.value }).then((res) => {
        if (res.data.code == 200) {
            tableData.value = res.data.data.childList
            total.value = res.data.data.totalCount
        }
    })
}

const getData = () => {
    currentPage.value = 1
    getList()
}

const goDetail = (row) => {
    console.log(row)
    router.push({
        path: '/page/routeController/index',
        query: {
            rid: 'EnterpriseServices/detailPages/ProjectRanking/ProjectRankingMonth',
            rTitle: '订单详情',
            companyPlatformId: companyPlatformId.value,
            orderYear: row.orderYear,
            projectCode: row.projectCode,
        },
    })
}

const init = async () => {
    getProjectList()
    getYearList()
    await getPlatList()
    getList()
}
init()

</script>


<style scoped lang="scss"></style>
